/***************************************************************************
   Filename:    breakout.h
   Author:      Josh Partridge
   Description: The file that includes the main method
****************************************************************************/

#include <iostream>
#include <string>

#include "Brush.h"
#include "Interface.h"
#include "MainMenu.h"
#include "StateMachine.h"
#include "helpers.h"
#include "Game.h"

using namespace std;

/************************************************************************************
 Name:               main
 Description:        Contains the state loop. stateMachine is an object instead of
                     simply an enumeratino so that we can pass a pointer to it into game

 *************************************************************************************/

int main ()
{
    // flag to kill the program itself, not the current game
    bool quit = false;

    //the user probably won't even see this, but just in case...
    cout << "loading . . .";


    // Keeps track of what state the program is in.
    StateMachine stateMachine;

    // instantiate our major objects
    // brush extends plotter
    Brush brush;
    // "interface" is apparently reserved, so we use "face"
    Interface face;
    MainMenu mainMenu;
    Game game(&stateMachine, &brush);

    //get rid of the loading message
    brush.clear();

    // Loop to check states
    while(!quit)
    {

        switch(stateMachine.getState())
        {
            case TITLE:        face.splashTitle(brush);
                               //wait for any key
                               getch();
                               //proceed to main menu
                               stateMachine.setState(MAIN_MENU);
                               break;

            case MAIN_MENU:    if(game.getLives()<1)
                                    mainMenu.lockContinue();
                               mainMenu.run(stateMachine, brush);
                               break;

            case NEW_GAME:     //Main menu will now have "continue" option
                               mainMenu.unlockContinue();
                               game.run();
                               break;

                               //resume the game loop, necessary when advancing a level
            case CONTINUE:     game.run();
                               break;

            case SCOREBOARD:   face.dispScoreboard(brush);
                               //default back to main menu when
                               //user leaves the instructions screen
                               stateMachine.setState(MAIN_MENU);
                               break;

            case INSTRUCTIONS: face.dispInstructions(brush);
                               //default back to main menu when
                               //user leaves the instructions screen
                               stateMachine.setState(MAIN_MENU);
                               break;


                               //don't let the user continue where they left off
            case GAME_OVER:    mainMenu.lockContinue();
                               //face.playAgain(brush);
                               stateMachine.setState(MAIN_MENU);
                               break;

            case QUIT:         quit = true;

            default:;
        }

    }

    return 0;
}
